//
//  ZLAlert+ZLImage.m
//  ZLAlert-OC
//
//  Created by 赵振磊 on 2024/1/3.
//

#import "ZLAlert+ZLImage.h"

@implementation ZLAlert (ZLImage)

- (ZLAlert *)addImage:(UIImage *)image {
    return [self addImage:image config:ZLAlertConfig.shared.imageConfig];
}

- (ZLAlert *)addImage:(UIImage *)image config:(ZLAlertItemConfig *)config {
    UIView *lastView = self.mainView.subviews.lastObject;
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.contentMode = UIViewContentModeScaleAspectFit;
    imageView.image = image;
    imageView.backgroundColor = config.backgroundColor;
    imageView.layer.cornerRadius = config.cornerRadius;
    imageView.layer.borderWidth = config.borderWidth;
    imageView.layer.borderColor = config.borderColor.CGColor;
    [self.mainView addSubview:imageView];
    
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mainView).offset(config.insets.left);
        make.right.equalTo(self.mainView).offset(-config.insets.right);
        if (lastView == nil) {
            make.top.equalTo(self.mainView).offset(config.insets.top);
        } else {
            make.top.equalTo(lastView.mas_bottom).offset(config.insets.top);
        }
    }];
    
    return [self layoutMainView:20];
}

@end
